#!/usr/bin/python
# -*- coding: UTF-8 -*-
__author__ = 'gtlions'
import sys


def collect(file):
    d = {}
    for line in open(file, 'r').readlines():
        left, right = line.split()
        if d.has_key(right):
            d[right].append(left)
        else:
            d[right]=[left]
    return d
if __name__ == "__main__":
    if len(sys.argv) == 1:
        print 'usage python kv.py file'
    else:
        result = collect(sys.argv[1])
        for left,right in result.items():
            print "%d '%s'\t=>\t%s" % (len(right), left, right)